package per.ethan.cloud.provider.api.fallback;

import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONUtil;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import per.ethan.cloud.common.domain.ErrorCodeVO;
import per.ethan.cloud.common.domain.ResultBean;
import per.ethan.cloud.provider.api.RemotePaymentService;
import per.ethan.cloud.provider.api.entity.Payment;

/**
 * @author Ethan
 * @date 2020/03/28 14:06
 */
@Slf4j
@Component
public class RemotePaymentServiceFallbackImpl implements RemotePaymentService {

    @Setter
    private Throwable cause;

    @Override
    public ResultBean<Long> save(Payment payment) {
        log.error("服务调用异常：{}", JSONUtil.toJsonStr(payment));
        cause.printStackTrace();
        return ResultBean.error(new ErrorCodeVO(HttpStatus.HTTP_INTERNAL_ERROR, "服务调用异常"));
    }

    @Override
    public ResultBean<Payment> getById(Long id) {
        log.error("服务调用异常：{}", id);
        cause.printStackTrace();
        return ResultBean.error(new ErrorCodeVO(HttpStatus.HTTP_INTERNAL_ERROR, "服务调用异常"));
    }

    @Override
    public ResultBean<String> feignTimeout() {
        log.error("服务调用异常");
        cause.printStackTrace();
        return ResultBean.error(new ErrorCodeVO(HttpStatus.HTTP_INTERNAL_ERROR, "服务调用异常"));
    }

    @Override
    public ResultBean<String> hello() {
        log.error("服务调用异常");
        cause.printStackTrace();
        return ResultBean.error(new ErrorCodeVO(HttpStatus.HTTP_INTERNAL_ERROR, "服务调用异常"));
    }
}
